package cn.changein.framework.modular.exportSetting.controller;

import cn.changein.framework.base.controller.BaseController;
import cn.changein.framework.base.pojo.page.PageInfo;
import cn.changein.framework.kernel.model.response.ResponseData;
import cn.changein.framework.modular.exportSetting.entity.ExportSetting;
import cn.changein.framework.modular.exportSetting.model.params.ExportSettingParam;
import cn.changein.framework.modular.exportSetting.service.ExportSettingService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 导出设置控制器
 *

 * @Date 2020-11-28 18:16:53
 * @Copyright: companyName
 * @Version 1.0
 * @Since JDK1.8
 */
@Controller
@RequestMapping("/exportSetting")
public class ExportSettingController extends BaseController {

    private String PREFIX = "/modular/exportSetting";

    @Autowired
    private ExportSettingService exportSettingService;

    /**
     * 跳转到主页面
     *

     * @Date 2020-11-28
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/exportSetting.html";
    }

    /**
     * 新增页面
     *

     * @Date 2020-11-28
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/exportSetting_add.html";
    }

    /**
     * 编辑页面
     *

     * @Date 2020-11-28
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/exportSetting_edit.html";
    }

    /**
     * 新增接口
     *

     * @Date 2020-11-28
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(ExportSettingParam exportSettingParam) {
        this.exportSettingService.add(exportSettingParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *

     * @Date 2020-11-28
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(ExportSettingParam exportSettingParam) {
        this.exportSettingService.update(exportSettingParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *

     * @Date 2020-11-28
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(ExportSettingParam exportSettingParam) {
        this.exportSettingService.delete(exportSettingParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *

     * @Date 2020-11-28
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(ExportSettingParam exportSettingParam) {
        ExportSetting detail = this.exportSettingService.getById(exportSettingParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *

     * @Date 2020-11-28
     */
    @ResponseBody
    @RequestMapping("/list")
    public PageInfo list(ExportSettingParam exportSettingParam) {
        return this.exportSettingService.findPageBySpec(exportSettingParam);
    }
    /**
     * 查询列表
     *

     * @Date 2020-11-28
     */
    @ResponseBody
    @RequestMapping("/export")
    public ResponseData export(@RequestParam("requestParam") String requestParam) {
        JSONObject jsonParam = JSONObject.parseObject(requestParam);
       return this.exportSettingService.getExportData(jsonParam);
    }
    /*

     * @Description //TODO 校验导出设置
     * @Date 2020-11-27 10:40
     * @MethodName validateTemplate
     * @Param [templateInfoParam]
     * @return cn.changein.framework.kernel.model.response.ResponseData
     **/
    @RequestMapping("/validateExportSetting")
    @ResponseBody
    public ResponseData validateExportSetting(ExportSettingParam exportSettingParam) {
        return this.exportSettingService.validateExportSetting(exportSettingParam);
    }
}


